/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Modified by Stefan Tillich, University of Bristol
 * - Adapted from TracksAdapter.java
 * - Changed package name
 */

package org.iacr.android.apps.yaea.ui;

import org.iacr.android.apps.yaea.provider.ScheduleContract;
import org.iacr.android.apps.yaea.provider.ScheduleContract.SyncColumns;

import org.iacr.android.apps.yaea.R;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.provider.BaseColumns;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

/**
 * A {@link android.widget.CursorAdapter} that renders a {@link RumpSessionQuery}.
 */
public class RumpSessionAdapter extends CursorAdapter {
    private static final int ALL_ITEM_ID = Integer.MAX_VALUE;

    private Activity mActivity;
    private boolean mHasAllItem;

    public RumpSessionAdapter(Activity activity) {
        super(activity, null);
        mActivity = activity;
    }

    public void setHasAllItem(boolean hasAllItem) {
        mHasAllItem = hasAllItem;
    }

    @Override
    public int getCount() {
        return super.getCount();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return super.getView(position, convertView, parent);
    }

    @Override
    public Object getItem(int position) {
        return super.getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return super.getItemId(position);
    }

    @Override
    public boolean isEnabled(int position) {
        return super.isEnabled(position);
    }

    @Override
    public int getViewTypeCount() {
    	return super.getViewTypeCount();
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    /** {@inheritDoc} */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
    	return mActivity.getLayoutInflater().inflate(R.layout.list_item_rumpsession_talk, parent,
                false);
    }

    /** {@inheritDoc} */
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
    	final TextView textView1 = (TextView) view.findViewById(android.R.id.text1);
    	textView1.setText(Integer.toString(cursor.getInt(RumpSessionQuery.RUMPSESSION_VOTE)));
    	
        final TextView textView2 = (TextView) view.findViewById(android.R.id.text2);
        textView2.setText(cursor.getString(RumpSessionQuery.RUMPSESSION_SPEAKER) + ": " + 
        		cursor.getString(RumpSessionQuery.RUMPSESSION_TITLE));
    }

    /**
     * {@link org.iacr.android.apps.yaea.provider.ScheduleContract.RumpSession} query parameters.
     */
    public interface RumpSessionQuery {
        int _TOKEN = 0x1; 
        
        String[] PROJECTION = {
        		BaseColumns._ID,
        		SyncColumns.UPDATED,
                ScheduleContract.RumpSession.RUMPSESSION_SPEAKER,
                ScheduleContract.RumpSession.RUMPSESSION_TITLE,
                ScheduleContract.RumpSession.RUMPSESSION_ORDER,
                ScheduleContract.RumpSession.RUMPSESSION_VOTE,
        };

        int _ID = 0;
        int UPDATED = 1;
        int RUMPSESSION_SPEAKER = 2;
        int RUMPSESSION_TITLE = 3;
        int RUMPSESSION_ORDER = 4;
        int RUMPSESSION_VOTE = 5;
    }
    
}
